using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DeckMove : MonoBehaviour
{
    public DeckMono deckMono;

    private Vector3 originSelf;
    private List<Vector3> originPoses;
    // Start is called before the first frame update
    void Start()
    {
        // StartCoroutine(UpdateCotoutine());
    }

    IEnumerator UpdateCotoutine()
    {
        while(true)
        {
            yield return new WaitForSeconds(1f);
            MoveDown();
            yield return new WaitForSeconds(1f);
            MoveUp();
        }
    }

    public void MoveDown()
    {
        originPoses = new List<Vector3>();
        for(int i = 0; i < deckMono.CardPositions.Count; ++i)
        {
            CardPosition cardPosition = deckMono.CardPositions[i];
            if(cardPosition.Pawn != null)
            {
                originPoses.Add(cardPosition.Pawn.transform.position);
                cardPosition.Pawn.transform.DOMoveZ(originPoses[i].z + 20f, 0.5f);
            }
            else
            {
                originPoses.Add(new Vector3(0, 0, 0));
            }
        }
        originSelf = transform.position;
        transform.DOMoveZ(originSelf.z + 20f, 0.5f);
    }

    public void MoveUp()
    {
        for (int i = 0; i < deckMono.CardPositions.Count; ++i)
        {
            CardPosition cardPosition = deckMono.CardPositions[i];
            if (cardPosition.Pawn != null)
            {
                cardPosition.Pawn.transform.DOMoveZ(originPoses[i].z, 0.5f);
            }
        }
        transform.DOMoveZ(originSelf.z, 0.5f);
    }
}
